home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_06 / saks / str.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  594 b   |  38 lines

  1. Listing 4 - class definition for a variable-length string
  2.  
  3. //
  4. // str.h - a variable-length string (interface)
  5. //
  6.  
  7. #include <iostream.h>
  8. #include <string.h>
  9.  
  10. class str
  11.     {
  12.     friend ostream &
  13.         operator<<(ostream &, const str &);
  14.     friend istream &
  15.         operator>>(istream &, str &);
  16. public:
  17.     str(const char * = "");
  18.     str(const str &);
  19.     ~str();
  20.     const str &operator=(const char *);
  21.     const str &operator=(const str &);
  22.     size_t length();
  23. private:
  24.     size_t len;
  25.     char *ptr;
  26.     };
  27.  
  28. inline str::~str()
  29.     {
  30.     delete [] ptr;
  31.     }
  32.  
  33. inline size_t str::length()
  34.     {
  35.     return len;
  36.     }
  37.  
  38.